package edu.asu.sapa.ground.update;

import edu.asu.sapa.Planner;
import edu.asu.sapa.ground.MathForm;
import edu.asu.sapa.ground.State;

public class PointLoader extends Load {
	public MathForm start;
	
	// change context?
	@Override
	public final boolean load(State s, Context c) {
		float t = start.value(s,c);
		float a = s.time;
		boolean possible=true;
		if (t <= a)
			for (Update u : contents) {
				possible&=u.updateBefore(s, c, a);
			}
		else
			s.events.add(c,this,UpdateWrapper.UpdateBefore,t);
//			for (Update u : contents) {
//				s.events.add(c,u,UpdateWrapper.UpdateBefore,t);
//			}
		return possible;
	}

	@Override
	public final boolean applicableBefore(State s, Context c) {
		float t = start.value(s,c);
		float a = s.time;
		boolean possible=true;
		if (t <= a)
			for (Update u : contents) {
				possible&=u.applicableBefore(s, c);
			}
		return possible;
	}
	
	@Override
	public final boolean applicableAfter(State s, Context c) {
		float t = start.value(s,c);
		float a = s.time;
		boolean possible=true;
		if (t <= a)
			for (Update u : contents) {
				possible&=u.applicableAfter(s, c);
			}
		return possible;
	}
	
	public String toString() {
		return "\t(at [" + start + "]" + super.toString();
	}

}
